package cn.hust.springboot.service.impl;

import cn.hust.springboot.bean.Dept;
import cn.hust.springboot.bean.DeptExample;
import cn.hust.springboot.bean.PositionExample;
import cn.hust.springboot.mapper.DeptMapper;
import cn.hust.springboot.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements IDeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public Dept getDeptById(Integer id) {
        return deptMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Dept> getAllDepts() {
        DeptExample example = new DeptExample();
        DeptExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return this.deptMapper.selectByExample(example);
    }

    @Override
    public int deleteDeptById(Integer id) {
        return deptMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int addDept(Dept dept) {
        return deptMapper.insert(dept);
    }

    @Override
    public int updateDept(Dept dept) {
        return deptMapper.updateByPrimaryKey(dept);
    }

    @Override
    public List<Dept> query(String deptName) {
        DeptExample example = new DeptExample();
        DeptExample.Criteria criteria = example.createCriteria();
        criteria.andNameLike("%"+deptName+"%");
        return this.deptMapper.selectByExample(example);
    }


}
